/**
 * @title: DegradeRuleMysqlConverter
 * @projectName mscloud
 * @Description TODO
 * @Author
 * @Date 2022/2/22 23:11
 */
package com.atguigu.springcloud.cloudsentinelgatewaydevelop.sentinel.convert.impl;

import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
import com.atguigu.springcloud.cloudsentinelgatewaydevelop.bean.dto.SentinelDegradeRuleDTO;
import com.atguigu.springcloud.cloudsentinelgatewaydevelop.sentinel.convert.PullConverter;
import lombok.Data;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;
@Data
@Component
public class DegradeRuleMysqlConverter implements PullConverter<List<SentinelDegradeRuleDTO>,List<DegradeRule>> {
    private long recommendRefreshMs=10000;
    @Override
    public List<DegradeRule> convert(List<SentinelDegradeRuleDTO> sources) {
        return sources.stream().map(
                item->{
                    DegradeRule degradeRule=new DegradeRule();
                    //JSONObject jsonObject = JSON.parseObject(item);
                    degradeRule.setCount(item.getCount());
                    degradeRule.setGrade(item.getGrade());
                    degradeRule.setMinRequestAmount(item.getMinRequestAmount());
                    degradeRule.setRtSlowRequestAmount(item.getRtSlowRequestAmount());
                    degradeRule.setTimeWindow(item.getTimeWindow());
                    degradeRule.setLimitApp(item.getLimitApp());
                    degradeRule.setResource(item.getResource());
                    return degradeRule;
                }
        ).collect(Collectors.toList());
    }
}
